﻿@using CarparkIMS_Model
@using X.PagedList.Mvc.Core
@using X.PagedList.Mvc.Core.Fluent
@using X.PagedList.Web.Common
@using X.PagedList
@model IEnumerable<llqqNumberPlate>
@{
    ViewData["Title"] = "泊車計時記錄";

    DateTime date = DateTime.Now;
    if (ViewBag.date!=null)
    {
        date = ViewBag.Date;
    }

    DateTime minDate = ViewBag.minDate ?? DateTime.Now.AddMonths(-3);
    DateTime maxDate = ViewBag.maxDate ?? DateTime.Now;

    long minSec = (long)ViewBag.MinSec;
}

<h1>泊車計時記錄</h1>

<form asp-controller="Journal" asp-action="ParkingPlaceLog" method="get">
    <p>
        搜尋: <input type="text" name="SearchString" />
        <input type="date" id="date" name="date" value="@date.ToString("yyyy-MM-dd")" min="@minDate.ToString("yyyy-MM-dd")" max="@maxDate.ToString("yyyy-MM-dd")">
        <input type="submit" value="篩選" />
    </p>
</form>
<table class="table">
    <thead class="bg">
        <tr>
            <th>
                <label class="label label-gray rounded"> 車位ID </label>
            </th>
            <th>
                <label class="label label-gray rounded"> 車牌號碼 </label>
            </th>
            <th>
                <label class="label label-gray rounded"> 開始時間 </label>
            </th>
            <th>
                <label class="label label-gray rounded"> 結束時間 </label>
            </th>
            <th>
                <label class="label label-gray rounded"> 持續時間 </label>
            </th> 
            <th>
                <label class="label label-gray rounded"> 創建時間 </label>
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            @if (item.EndDatetime == null || item.DurationTimespan > minSec)
            {
                <tr>
                    <td>
                        <span class="text-dark text-bold">@item.ParkingPlaceSharpNumber</span><span class="text-light">/@item.ParkingPlaceId</span><span class="text-light">/@item.ID</span>
                    </td>
                    <td>
                        @item.NumberPlate
                    </td>
                    <td>
                        @if (item.StartDatetime == null)
                        {
                            <label class="label label-gray rounded"> 不符合規則的記錄 </label>
                        }
                        else
                        {
                            <label class="label label-gray rounded">
                                @Html.Raw(string.Format("{0:dd/MM/yyyy}",item.StartDatetime))
                                <span claSS='text-primary'> @Html.Raw(string.Format("{0:HH:mm:ss}",item.StartDatetime)) </span>
                                <span class="text-light">/ @item.LogIdOfStart</span>
                            </label>
                        }
                    </td>
                    <td>
                        @if (item.EndDatetime == null)
                        {
                            <label class="label label-gray rounded"> 車輛未離開 </label>
                        }
                        else
                        {
                            <label class="label label-gray rounded">
                                @Html.Raw(string.Format("{0:dd/MM/yyyy}",item.EndDatetime))
                                <span claSS='text-primary'> @Html.Raw(string.Format("{0:HH:mm:ss}",item.EndDatetime)) </span>
                                <span class="text-light">/ @item.LogIdOfEnd</span>
                            </label>
                        }
                    </td>
                    <td>
                        @if (item.DurationTimespan == 0)
                        {
                            <label class="label label-gray rounded"> - </label>
                        }
                        else
                        {
                            TimeSpan timeSpan = TimeSpan.FromSeconds(item.DurationTimespan);
                            <label class="label label-gray rounded"> @timeSpan</label>
                        }
                    </td>
                    <td>
                        <label class="label label-gray rounded">@string.Format("{0:dd/MM/yyyy HH:mm:ss}",item.CreatedOn) </label>
                    </td>
                </tr>
            }
            
        }
    </tbody>
</table>
@if (ViewBag.Page > 1)
{
    <div class="page-header btn-xs">
        @Html.PagedListPager((IPagedList)Model, page => Url.Action("ParkingPlaceLog", new
        {
        page = page,
        Date = ViewBag.Date,
        SearchString= ViewBag.SearchString,
        }),new PagedListRenderOptions {LiElementClasses = new string[] { "page-item" }, PageClasses = new string[] { "page-link" }})
    </div>
}
